class ListNode2 {
    int val;
    ListNode2 next;
    ListNode2 head;

    ListNode2() {
    }

    ListNode2(int val) {
        this.val = val;
    }

    ListNode2(int val, ListNode2 next) {
        this.val = val;
        this.next = next;
    }
}

public class Java1016_02 {
public ListNode2 middleNode(ListNode2 head) {
    ListNode2 fast = head;
    ListNode2 slow = head;
    while (fast != null && fast.next != null){
        fast = fast.next.next;
        slow = slow.next;
    }

    return slow;
}

    public static void main(String[] args) {

        ListNode2 x1 = new ListNode2(12);
        ListNode2 x2 = new ListNode2(23);
        ListNode2 x3 = new ListNode2(34);
        ListNode2 x4 = new ListNode2(45);
        ListNode2 x5 = new ListNode2(56);

        x1.next = x2;
        x2.next = x3;
        x3.next = x4;

        final ListNode2 head = x1;

        Java1016_02 x = new Java1016_02();

        System.out.println((x.middleNode(head)).val);

    }

}
